// pages/merchant-introduction/introduction.js
import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ID:'',
    shoplist:'',
    isatt:'',
  },
  //关注
  guanzhu:function(){
    if (this.data.isatt > 0){
    ajax('/api/MyCollection/AttentionShop?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      ShopID: this.data.ID,
      VType: 2
    }), {
        header: {
          'Accept': 'application/x-www-form-urlencoded', // 默认值
        },
        method: "post",
      }, res => {
        console.log(res,'res')
        this.getlist()
      })
    }else{
      ajax('/api/MyCollection/AttentionShop?requestContent=' + JSON.stringify({
        token: wx.getStorageSync('Access_token'),
        ShopID: this.data.ID,
        VType: 1
      }), {
          header: {
            'Accept': 'application/x-www-form-urlencoded', // 默认值
          },
          method: "post",
        }, res => {
          console.log(res, 'res')
          this.getlist()
        })
    }
  },
  //联系商家
  lianxishangjia:function(e){
    var phone=e.currentTarget.dataset.phone
    wx.makePhoneCall({
      phoneNumber: phone //仅为示例，并非真实的电话号码
    })
  },
  //获取店铺信息
  getlist:function(){
    ajax('/api/ShopProduct/GetShopDetail?requestContent=' + JSON.stringify({
      token: wx.getStorageSync("Access_token"),
      ShopID: this.data.ID
    }), {
        header: {
          'Accept': 'application/x-www-form-urlencoded', // 默认值
        },
        method: "get",
      }, res => {
        // console.log(res)
        this.setData({shoplist: res.Models})
        for(var a in this.data.shoplist){
          // console.log(this.data.shoplist[a].IsAttention)
          this.setData({
            isatt: this.data.shoplist[a].IsAttention
          })
        }
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#000',
    })
    var ID = options.ID
    this.setData({
      ID: ID
    })
    this.getlist()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})